<?php
defined('BASEPATH') OR exit('No direct script access allowed');

?>

<div class="row" style="margin-bottom:10px;">
                                    <div class=" col-sm-6">
                                        <?php echo form_open(current_url(), array('class' => 'form-inline', 'method'=>'get', 'id' => 'search_goods')); ?>                                    
                                        
                                        <div class="form-group" style="margin-right:15px;">
                                         <?php echo form_input($keyword);?>
                                        </div>
                                        <div class="form-group" >
                                            <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-sm btn-primary btn-flat', 'content' => "搜索网站")); ?>    
                                        </div>
                                        
                                        
                                        <?php echo form_close();?>
                                    </div>

                                    <div class=" col-sm-6 form-inline pull-right" style="line-height:30px;font-size:12px;text-align:right;">
                                        <?php echo '共'.$total.'条数据，'.$page.'/'.$pages.'页';?> 
                           
                                        <select id="pagesize" class="form-control input-sm" style="height:22px;">
                                            <option value="0">每页数量</option>
                                            <option value="50">50</option>
                                            <option value="100">100</option>
                                            <option value="200">200</option>
                                            <option value="500">500</option>
                                        </select>
                                       
                                        <input type="text" id="topage" value="" class="form-control input-sm" placeholder='页码' style="margin:0 5px;height:22px;width:45px;"> 
                                        <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-xs btn-primary btn-flat', 'id'=>'jumpbtn','content' => "跳转")); ?>
                                    </div>

</div>
                    <div class="row">
                                  

                        <div class="col-sm-12">
                             <div class="box">
                                
                                <div class="box-body">
                                   
                                    <table class="table table-striped table-hover" style="margin-top:20px;">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>域名</th>
                                                <th>标题</th>
                                                <th>描述</th>
                                                <th>关键字</th>
                                                <th>类别</th>
                                            </tr>
                                        </thead>
                                        <tbody id="listtable">
<?php foreach ($data as $item):?>
<tr>
    <td><?php echo $item["id"]; ?></td>
    <td><a href="http://<?php echo $item["domain"]; ?>" target="_blank"><?php echo $item["domain"]; ?></a></td>
    <td width="20%"><?php echo $item["title"]; ?></td>
  
    <td width="40%"><?php echo $item["description"]; ?></td>
    <td width="20%"><?php echo $item["keyword"]; ?></td>
    <td><?php echo $item["sitetype"]; ?></td>
</tr>
<?php endforeach;?>
                                        </tbody>
                                    </table>
                                    <?php 
                                    if(empty($data)){
                                        echo "<h2 style='text-align:center;padding:50px 0;'>没有查询到数据</h2>";
                                    }
                                    ?>
                                    <?php echo $pager;?>
                                </div>
                            </div>
                         </div>
                    </div>

                    <script>
$(function(){
    function changeURLArg(url, arg, arg_val) {
        var pattern = arg + '=([^&]*)';
        var replaceText = arg + '=' + arg_val;
        if (url.match(pattern)) {
            var tmp = '/(' + arg + '=)([^&]*)/gi';
            tmp = url.replace(eval(tmp), replaceText);
            return tmp;
        } else {
            if (url.match('[\?]')) {
                return url + '&' + replaceText;
            } else {
                return url + '?' + replaceText;
            }
        }
        return url + '\n' + arg + '\n' + arg_val;
    }

    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); 
        var r = window.location.search.substr(1).match(reg); 
        if (r != null) return unescape(r[2]); return null;
    }

    $("select#pagesize").change(function(){
        pagesize=$("select#pagesize option:selected").val();
        if(pagesize>0)
        {
            var url= window.location.href;
            var newUrl=  changeURLArg(url, "pagesize", pagesize); 
            window.location.href =  newUrl;
        }
    });
    $("#jumpbtn").on("click",function(){
        topage=$("#topage").val();
        if(topage>0)
        {
            var url= window.location.href;
            var newUrl=  changeURLArg(url, "page", topage); 
            window.location.href =  newUrl;
        }
    });
});
</script>
<?php if($keyword){
    ?>

<script>
$(function(){
   
    require(['jquery','jquery.mark.min'], function($){
        var keyword = $("#keyword").val();
        var options = {
		      "className": "match"
		    };
        $("#listtable").mark(keyword, options);
    });
});
</script>
<?php
}
?>